package com.april.pattern.creational.singleton;

/**
 * @author April
 * @version V1.0.0
 * @date 2019/06/23 09:22
 * @description 懒汉式
 */
public class LazySingleton {
    private static LazySingleton lazySingleton = null;

    private LazySingleton() {

    }

    /**
     * 如果不加synchronize则多线程下是不安全的

     * @return LazySingleton
     */
    public synchronized static LazySingleton getInstance() {
        if (lazySingleton == null) {
            lazySingleton = new LazySingleton();
        }

        return lazySingleton;
    }
}
